PCA Index Interactive Visualization Examples

PCA Index Interactive Visualization Examples#

import plotly.express as px

import config
import load_fred
import pca_index

DATA_DIR = config.DATA_DIR

import warnings
warnings.filterwarnings('ignore')
df = load_fred.load_fred(data_dir=DATA_DIR)
dfn = pca_index.transform_series(df)
## Visualize Principal Component 1
pc1, loadings = pca_index.pca(dfn, module="scikitlearn")
pc1.plot(color="red")
<Axes: xlabel='DATE'>
../_images/577a31395e279486f1ae1a52b731494e5e7ab2305642841f566020532aee7797.png
# Simple version
fig = px.line(pc1)
fig.show()
# Using slider and quick views
pca_index.pc1_line_plot(pc1)
## Visualize normalized and raw series
dfn.plot(subplots=True, figsize=(10, 10));
../_images/a7fc9b8dfc90524ca37dc80b0148555c60d9d90fa77b748a00379c8dfbc22a85.png
fig = px.line(dfn, facet_col="variable", facet_col_wrap=1)
fig.update_yaxes(matches=None)
fig.show()
pca_index.plot_unnormalized_series(df)
pca_index.plot_normalized_series(dfn)